$(function () {

    var isWechatPay = $('#doc').data('value') === 0;

    var isWechatBrowser = function () {
        var ua = navigator.userAgent.toLowerCase();
        if (ua.match(/MicroMessenger/i) == "micromessenger") {
            return true;
        } else {
            return false;
        }
    };

    if (isWechatBrowser()) {
        if (isWechatPay) {
            $('#info').removeClass('hidden');
            wx.config({
                debug: false,
                appId: "{$signParams['appId']}",
                timestamp: "{$signParams['timestamp']}",
                nonceStr: "{$signParams['nonceStr']}",
                signature: "{$signParams['signature']}",
                jsApiList: ['chooseWXPay']
            });

            wx.ready(function () {
                // 确定支付按钮
                $('#pay').on('click', function (e) {
                    e.preventDefault();
                    wx.chooseWXPay({
                        timestamp: "{$payParams['timeStamp']}",
                        nonceStr: "{$payParams['nonceStr']}",
                        package: "{$payParams['package']}",
                        signType: "{$payParams['signType']}",
                        paySign: "{$payParams['paySign']}",
                        success: function (res) {
                            var booknumber = $('#doc').attr('data-booknumber');
                            location.href = '/Wechat/BookingPage/paysuccess.html?bn=' + booknumber;
                        }
                    });
                });
            });
            $('#pay').on('click', function (e) {
                e.preventDefault();
                // jssdk
            });
        } else {
            $('#error').removeClass('hidden');
        }
    } else {
        if (isWechatPay) {
            $('#errorContent').html(lang('wechatPay'));
            $('#error').removeClass('hidden');
        } else {
            $('#info').removeClass('hidden');
        }
    }
});
